import { AttachmentData, WidgetOption, WidgetStyle, WidgetType } from '@/types'
import WidgetAttachment from './WidgetAttachment.vue'
import AttachmentFill from './AttachmentFill.vue'

export default {
  key: 'attachment',
  name: '附件',
  type: WidgetType.ATTACHMENT,
  style: WidgetStyle.FILL,
  icon: 'fa-icon-widget-attachment',
  width: 140,
  height: 30,
  component: WidgetAttachment,
  fillingComponent: AttachmentFill,

  usingValidate(widget) {
    if (widget.required && !widget.hasFillValue) return `请上传附件文件`
  },

  clear(widget) {
    Object.assign(widget.attachment, {
      fileName: '',
      loading: false,
      progress: 0
    } as AttachmentData)
  }
} as WidgetOption
